<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入店铺名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="店铺类型" prop="name">
        <el-select v-model="queryParams.trade" placeholder="请选择" clearable @change="handleQuery">
          <el-option v-for="item in storeTypeArr" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd"
          v-hasPermi="['mall:mallStore:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
          v-hasPermi="['mall:mallStore:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['mall:mallStore:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['mall:mallStore:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallStoreList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店铺名称" align="center" prop="name" />
      <el-table-column label="店铺类型" align="center" prop="typeInfo.name" />
      <el-table-column label="店铺经营模式" align="center">
        <template #default="scope">
          {{ scope.row.businessModel == 1 ? "线上(快递)" : "线下(核销)" }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="店铺入驻类型" align="center">
        <template #default="scope">
          {{ scope.row.trade == 1 ? "会员自营" : "优质商家" }}
        </template>
      </el-table-column> -->
      <el-table-column label="店铺logo" align="center">
        <template #default="scope">
          <ImagePreview :src="scope.row.logo"></ImagePreview>
        </template>
      </el-table-column>
      <el-table-column label="店铺门头照" align="center">
        <template #default="scope">
          <ImagePreview :src="scope.row.doorHead"></ImagePreview>
        </template>
      </el-table-column>
      <el-table-column label="店铺收款码" align="center">
        <template #default="scope">
          <ImagePreview :src="scope.row.shopCode"></ImagePreview>
        </template>
      </el-table-column>
      <el-table-column label="店铺状态" align="center">
        <template #default="scope">
          <span>{{ scope.row.state == 0 ? "未营业" : "营业中" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺联系人姓名" align="center" prop="linkerName" />
      <el-table-column label="店铺联系人电话" align="center" prop="linkerMobile" />
      <!-- <el-table-column label="店铺让利比例" align="center" prop="discountRate" /> -->
      <el-table-column label="支付宝" align="center" prop="createUserTemp.storeZfbNickName" />
      <el-table-column label="审核状态" align="center">
        <template #default="scope">
          <span>{{
            scope.row.verifyState == 0
              ? "未审核"
              : scope.row.verifyState == 1
                ? "审核通过"
                : "审核不通过"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center">
        <template #default="scope">
          <span>{{ scope.row.verifyUserTemp?.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="verifyTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.verifyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核备注" align="center" prop="verifyRemark" />
      <el-table-column label="创建人信息" align="center">
        <template #default="scope">
          <p>用户:{{ scope.row.createUserTemp?.userName }}</p>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="orderBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:mallStore:edit']">修改</el-button>
          <el-button link type="primary" icon="UserFilled" @click="handleExamine(scope.row)"
            v-hasPermi="['mall:mallStore:examine']" v-if="scope.row.verifyState == 0">审核</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallStore:remove']">删除</el-button>
          <el-button link type="primary" @click="goMallSpu(scope.row)">商品列表</el-button>
          <el-button v-if="scope.row.ledgerStatus !== 1 && scope.row.ledgerStatus !== 2 && scope.row.subMchId" link
            type="primary" @click="goApplication(scope.row)">分账</el-button>
          <el-button v-if="scope.row.ledgerStatus == 1" link type="primary" @click="gobind(scope.row)">分账绑定</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改店铺对话框 -->
    <el-dialog :title="title" v-model="open" width="80%" append-to-body>
      <el-form ref="mallStoreRef" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="店铺名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入店铺名称" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="店铺定位" label-width="120">
              <el-input :value="form.lon + ',' + form.lng" @click="mapShow = true" />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="店铺类型" prop="type" label-width="110px">
              <el-select v-model="form.type">
                <el-option v-for="item in storeTypeList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="经营模式" prop="businessModel" label-width="110px">
              <el-select v-model="form.businessModel">
                <el-option v-for="item in storeBusinessArr" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="店铺入驻类型" prop="trade" label-width="110px">
              <el-select v-model="form.trade">
                <el-option v-for="item in storeTypeArr" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="是否开启余额支付" prop="openBalancePay" label-width="130px">
              <el-radio-group v-model="form.openBalancePay">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否开启熵豆支付" prop="openShangdouPay" label-width="130px">
              <el-radio-group v-model="form.openShangdouPay">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.ledger == 0 || form.ledger == null">
            <el-form-item label="分账比例" prop="ledgerRate" label-width="130px">
              <el-input-number v-model="form.ledgerRates" :min="1" :max="form.maxRate * 100"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺联系人姓名" prop="linkerName" label-width="120">
              <el-input v-model="form.linkerName" placeholder="请输入店铺联系人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺联系人电话" prop="linkerMobile" label-width="126">
              <el-input v-model="form.linkerMobile" placeholder="请输入店铺联系人电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="route.query.prefecture == 2">
            <el-form-item label="关联用户" prop="createBy" label-width="126">
              <el-select v-model="form.createBy" filterable remote placeholder="请搜索并选择" :remote-method="getUserList"
                style="width: 240px">
                <el-option v-for="item in userList" :key="item.userId" :label="item.userName" :value="item.userId" />
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="开户行名称" prop="openName" label-width="100">
              <el-input v-model="form.openName" placeholder="请输入开户行名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开户银行" prop="openBank" label-width="90">
              <el-input v-model="form.openBank" placeholder="请输入开户银行" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开户行账号" prop="openBankCard" label-width="100">
              <el-input v-model="form.openBankCard" placeholder="请输入开户行账号" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="店铺详细地址" prop="address" label-width="110">
              <!-- <el-input v-model="form.address" placeholder="请输入店铺详细地址" /> -->
              <el-input class="width100" v-model="form.address" enter-button="查找位置" placeholder="请查找位置">
                <!--<el-button-->
                <!--slot="append"-->
                <!--style="background: #46a6ff; color: #fff; border-radius: 0 4px 4px 0;"-->
                <!--@click="onSearchs"-->
                <!--&gt;查找位置</el-button>-->
              </el-input>
              <iframe id="mapPage" width="100%" height="500px" frameborder="0" :src="keyUrl" />
            </el-form-item>

          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="店铺logo" prop="logo">
              <ImageUpload v-model="form.logo" :limit="1"></ImageUpload>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="营业执照上传" prop="businessLicense" label-width="108">
              <ImageUpload v-model="form.businessLicense" :limit="1"></ImageUpload>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺门头照" prop="logo" label-width="doorHead">
              <ImageUpload v-model="form.doorHead" :limit="1"></ImageUpload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="店铺內景照" prop="inDoorOne" label-width="98">
          <ImageUpload v-model="form.inDoorOne"></ImageUpload>
        </el-form-item>
        <el-form-item label="店铺介绍" prop="detail" label-width="98">
          <el-input v-model="form.detail" placeholder="请输入店铺介绍" />
        </el-form-item>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog title="选择经纬度" v-model="mapShow" width="80%" append-to-body>
      <ChooseLocation :lat="form.lon" :lnt="form.lng" @getPosition="getPosition"></ChooseLocation>
    </el-dialog>
    <el-dialog title="分账绑定" v-model="bindShow" width="40%" append-to-body>
      <el-form ref="bindFormRef" :model="bindForm" :rules="bindRules" label-width="120">
        <el-form-item label="分账接收方选择" prop="acctName">
          <el-tag v-show="bindApply.acctName">已选择:{{ bindApply.acctName }}</el-tag>
          <el-button @click="openApply" size="mini">选择</el-button>
        </el-form-item>
        <el-form-item label="最大分账比例" prop="maxRate">
          <el-input-number controls-position="right" :step="1" :min="1" :max="100" style="width:100px"
            v-model="bindForm.maxRate">
          </el-input-number>
          <span>&nbsp;&nbsp;&nbsp;&nbsp;%</span>
        </el-form-item>
        <el-form-item label="合作协议名称" prop="entrustFileName">
          <el-input style="width:200px" placeholder="请输入内容" v-model="bindForm.entrustFileName">
          </el-input>
          <span>&nbsp;&nbsp;&nbsp;&nbsp;示例:富乐万家/大白的茶果咖分账协议</span>
        </el-form-item>
        <el-form-item label="合作协议附件" prop="entrustFilePath" label-width="120">
          <ImageCropUpload :enlarge="3" :width="800" :height="1500" v-model="bindForm.entrustFilePath" :isYuji="true" :isBind="true"
            :params="{ sub_mch_id: bindForm.merCupNo }"></ImageCropUpload>
          <!-- <FileUploadYuji v-model="form.entrustFileName"  :limit="1" :isYuji="true" :fileType="['doc','docx']" :fileSize="500"></FileUploadYuji> -->
        </el-form-item>
        <!-- <el-form-item label="合作协议附件路径" prop="verifyRemark">
          <FileUpload v-model="form.video" :limit="1" :fileType="['mp4', 'flv', 'm3u8']" :fileSize="500"></FileUpload>
        </el-form-item> --> 
      </el-form>
      <template #footer>
        <div class="footer">
          <el-button type="primary" class="center" @click="submitBind">提交</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog title="选择接收方" v-model="applyShow" width="90%" append-to-body>
      <el-table v-loading="loading" :data="withdrawRecordList">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="分账接收方名称" width="120" align="center" prop="receiverName" />
        <el-table-column label="联系手机号" align="center" prop="contactMobile" />
        <el-table-column label="对公对私" align="center" prop="acctTypeCode" />
        <el-table-column label="营业执照号码" align="center" prop="licenseNo" />
        <el-table-column label="营业执照名称" align="center" prop="licenseName" />
        <el-table-column label="法人姓名" align="center" prop="legalPersonName" />
        <el-table-column label="法人证件类型" align="center" prop="legalPersonCertificateType" />
        <el-table-column label="法人证件号" align="center" prop="legalPersonCertificateNo" />
        <el-table-column label="收款账户卡号" align="center" prop="acctNo" />
        <el-table-column label="收款账户名称" align="center" prop="acctName" />
        <el-table-column label="收款账户证件类型" align="center" prop="acctCertificateType" />
        <el-table-column label="收款账户证件号" align="center" prop="acctCertificateNo" />
        <el-table-column label="收款账户开户行号" align="center" prop="acctOpenBankCode" />
        <el-table-column label="收款账户开户名称" align="center" prop="acctOpenBankName" />
        <el-table-column label="收款账户清算行行号" align="center" prop="acctClearBankCode" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" icon="Edit" @click="handleAudit(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />

    </el-dialog>
    <el-dialog title="店铺审核" v-model="storeExamine" width="500px" append-to-body>
      <el-form ref="examineFormsRef" :model="examineForms" label-width="80px">
        <el-form-item label="审核状态" prop="verifyState">
          <el-radio-group v-model="examineForms.verifyState">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核备注" prop="verifyRemark">
          <el-input v-model="examineForms.verifyRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="exanmineSubmitForm">确 定</el-button>
          <el-button @click="exanmineCancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="MallStore">
import {
  listMallStore,
  getMallStore,
  delMallStore,
  addMallStore,
  updateMallStore,
  mallStoreVerify,
  addApplication,
  applyBind
} from "@/api/mall/mallStore";

import {
  childrenByCode
} from "@/api/system/type"
import { listWithdrawRecord } from "@/api/money/recipientList";


import {
  innerListUser
} from "@/api/system/user"
const { proxy } = getCurrentInstance();

const mallStoreList = ref([]);
const withdrawRecordList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const mapShow = ref(false);
const bindShow = ref(false);
const applyShow = ref(false);

const storeExamine = ref(false);
const examineForms = ref({});
const bindApply = ref({});
const bindForm = ref({});
const router = useRouter();
const route = useRoute();
const storeTypeArr = ref([
  {
    value: 1,
    label: "会员自营",
  },
  {
    value: 2,
    label: "优质商家",
  },
]);
// 店铺经营模式
const storeBusinessArr = ref([
  {
    value: 1,
    label: "线上(快递)",
  },
  {
    value: 2,
    label: "线下(核销)",
  },
])


const data = reactive({
  form: {},
  keyUrl: '',
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null,
    profile: null,
    detail: null,
    logo: null,
    cover: null,
    type: null,
    trade: null,
    prefecture: route.query && route.query.prefecture,
    doorHead: null,
    inDoorOne: null,
    inDoorTwo: null,
    lon: null,
    lng: null,
    address: "",
    orderBy: null,
    state: null,
    linkerName: null,
    linkerMobile: null,
    verifyState: null,
    verifyBy: null,
    verifyTime: null,
    verifyRemark: null,
    deptId: null,
    isDelete: null,
    openBank: null,
    openName: null,
    openBankCard: null,
    businessLicense: null,
  },
  rules: {
    name: {
      required: true,
      message: "请输入店铺名称",
      trigger: "blur",
    },
    // discountRate: {
    //   required: true, message: "请输入店铺让利比例", trigger: "blur"
    // },
    address: {
      required: true,
      message: "请输入详细地址",
      trigger: "blur",
    },
    linkerName: {
      required: true,
      message: "请输入联系人姓名",
      trigger: "blur",
    },
    linkerMobile: {
      required: true,
      message: "请输入联系人手机号",
      trigger: "blur",
    },
    openBank: {
      required: true,
      message: "请输入开户银行",
      trigger: "blur",
    },
    openName: {
      required: true,
      message: "请输入开户行名称",
      trigger: "blur",
    },
    openBankCard: {
      required: true,
      message: "请输入开户行账号",
      trigger: "blur",
    },
    logo: {
      required: true,
      message: "请上传店铺logo",
      trigger: "blur,change",
    },
    businessLicense: {
      required: true,
      message: "请上传营业执照",
      trigger: "blur,change",
    },
    doorHead: {
      required: true,
      message: "请上传门头照",
      trigger: "blur,change",
    },
    inDoorOne: {
      required: true,
      message: "请上传店内环境图",
      trigger: "blur,change",
    },
  },
  bindRules: {
    acctName: {
      required: true,
      message: "请选择分账接收方",
      trigger: "blur",
    },
    maxRate: {
      required: true,
      message: "请输入分账比例",
      trigger: "blur",
    },
    sub_mch_id: {
      required: true,
      message: "请输入分账方",
      trigger: "blur",
    },
    entrustFilePath: {
      required: true,
      message: "请上传分账方授权书",
      trigger: "blur,change",
    },
  }
});

const { queryParams, form, rules, keyUrl, bindRules } = toRefs(data);

/**
 * 绑定用户
 */
const userList = ref([])
function getUserList(userName = "") {
  innerListUser({
    userName
  }).then((res) => {
    userList.value = res.rows;
  });
}
getUserList();



/**
 * 店铺类型
 */
const storeTypeList = ref([]);
function getStoreTypeList() {
  childrenByCode({
    code: "merchantClassification"
  }).then(res => {
    storeTypeList.value = res.data;
  })
}
getStoreTypeList()

function openApply() {
  applyShow.value = true;
  getBindList();
}

function handleAudit(row) {
  applyShow.value = false;
  bindApply.value = row;
  bindForm.value.receiverNo = row.receiverNo;
  bindForm.value.acctName = row.acctName;
}

function goMallSpu(row) {
  router.push({
    path: "/mall/mallSpu",
    query: { storeId: row.id, columnType: route.query.columnType },
  });
}

//分账
function goApplication(row) {
  addApplication({
    sub_mch_id: row.subMchId
  }).then((res) => {
  });

}
//分账绑定
function gobind(row) {
  bindForm.value = {
    maxRate: 10,
    merCupNo: row.subMchId
  }
  bindShow.value = true
}



function examineReset() {
  console.log(123)
  examineForms.value = {
    id: null,
    verifyState: 1,
    verifyRemark: "",
  };
  proxy.resetForm("examineFormsRef");
}

function exanmineSubmitForm() {
  proxy.$refs["examineFormsRef"].validate((valid) => {
    if (valid) {
      mallStoreVerify(examineForms.value).then((res) => {
        proxy.$modal.msgSuccess("操作成功");
        storeExamine.value = false;
        getList();
      });
    }
  });
}

function exanmineCancel() {
  storeExamine.value = false;
  examineReset();
}

function handleExamine(row) {
  examineForms.value.id = row.id;
  storeExamine.value = true;
}

/** 查询店铺列表 */
function getList() {
  loading.value = true;
  keyUrl.value = `https://apis.map.qq.com/tools/locpicker?type=1&key=YT2BZ-V6MW3-YU33F-OH7AK-RQN67-IGFCM&referer=myapp&policy=1&total=100`;
  listMallStore(queryParams.value).then((response) => {
    mallStoreList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 查询分账方列表 */
function getBindList() {
  listWithdrawRecord(queryParams.value).then((response) => {
    withdrawRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    name: null,
    profile: null,
    detail: null,
    logo: null,
    cover: null,
    type: null,
    trade: null,
    prefecture: route.query && route.query.prefecture,
    doorHead: null,
    inDoorOne: null,
    inDoorTwo: null,
    lon: "",
    lng: "",
    address: null,
    orderBy: null,
    state: null,
    linkerName: null,
    linkerMobile: null,
    verifyState: null,
    verifyBy: null,
    verifyTime: null,
    verifyRemark: null,
    deptId: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    isDelete: null,
    discountRate: null,
    openBalancePay: null,
    createBy: null,
    openShangdouPay: null
  };
  proxy.resetForm("mallStoreRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加店铺";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value;
  getMallStore(_id).then((response) => {
    form.value = response.data;
    form.value.ledgerRates = response.data.ledgerRate * 100;
    open.value = true;
    title.value = "修改店铺";
  });
}

function getPosition(position) {
  form.value.lon = position.lat;
  form.value.lng = position.lng;
  mapShow.value = false;
}


/** 分账绑定 */
function submitBind() {
  proxy.$refs["bindFormRef"].validate((valid) => {
    if (valid) {
      let maxRate = bindForm.value.maxRate / 100;
      applyBind(maxRate, bindForm.value).then((response) => {
        proxy.$modal.msgSuccess("申请已受理");
        bindShow.value = false;
      });
    }
  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["mallStoreRef"].validate((valid) => {
    if (valid) {
      if (form.value.id != null) {
        form.value.ledgerRate = form.value.ledgerRates / 100;
        updateMallStore(form.value).then((response) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addMallStore(form.value).then((response) => {
          // form.value.ledgerRate = response.data.ledgerRates / 100;
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm('是否确认删除店铺编号为"' + _ids + '"的数据项？')
    .then(function () {
      return delMallStore(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => { });
}
// 选择经纬度
function selectAdderss(data) {
  // form.value.address = data.poiaddress + data.poiname;
  form.value.latitude = data.latlng.lat;
  form.value.longitude = data.latlng.lng;
}

/** 导出按钮操作 */
window.addEventListener(
  'message',
  function (event) {
    // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
    var loc = event.data;
    if (loc && loc.module === 'locationPicker') {
      // 防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
      // window.parent.selectAdderss(loc);
      selectAdderss(loc)
    }
  },
  false,
);
getList();
</script>
